#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-10-14 9:30 上午
# @Author  : yangdy
# @File    : 2020-10-14.1002.查找常用字符
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def commonChars(self, A: List[str]) -> List[str]:
        if not A:
            return []
        c = [0 for i in range(26)]
        for si in A[0]:
            c[ord(si)-ord('a')] += 1
        for ii in range(1, len(A)):
            ai = A[ii]
            ci = [0 for i in range(26)]
            for si in ai:
                ci[ord(si)-ord('a')] += 1
            for i in range(26):
                c[i] = min(c[i], ci[i])
        ans = []
        for i in range(26):
            for j in range(c[i]):
                ans.append(chr(ord('a')+i))
        return ans
